package classifiers;

import mulan.classifier.MultiLabelLearner;
import utils.TagCluster;
import utils.TagClustering;
import utils.Utils;
import weka.core.SerializationHelper;

public class TwoLevelClassifierLoader {
	
	private String directory;
	private TagClustering tc;
	private DatasetDescription level_one_description,level_two_description;

	public TwoLevelClassifierLoader(String directory,
			DatasetDescription level_one_description,
			DatasetDescription level_two_description,
			TagClustering tc) {
		super();
		this.directory = directory;
		this.level_one_description = level_one_description;
		this.level_two_description = level_two_description;
		this.tc = tc;
	}
	
	public TwoLevelClassifier loadClassifier() {
		TwoLevelClassifier res = new TwoLevelClassifier();
		String level_one_model_name = Utils.getNameForLevelOne(level_one_description)+".model";
		try {
			res.setLevel_one_classifier((MultiLabelLearner) SerializationHelper.read(directory+level_one_model_name));
			for ( TagCluster cluster : tc.getAllClusters() ) {
				String level_two_model_name = Utils.getNameForLevelTwo(level_two_description,cluster)+".model";
				res.setLevelTwoClassifierForCluster(tc.getClusterIdx(cluster.toString()),((MultiLabelLearner) SerializationHelper.read(directory+level_two_model_name)));	
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}

}
